<?php
/**
 * Created by PhpStorm.
 * User: hao
 * Date: 2018/10/29
 * Time: 11:22 AM
 */

namespace app\api\controller\v1;

use app\api\controller\BaseController;
use app\api\model\Category as CategoryModel;

class Category extends BaseController
{

    protected $beforeActionList = [
        'checkPrimaryScope' => ['only' => 'getAllCategories']
    ];

    public function getAllCategories() {
        $categories = CategoryModel::all([],'img');
        $data = collection($categories);
        if ($data->isEmpty()) {
            throw new CategoryException();
        }
        return $data;
    }

    public function getDetailCategories() {
        $categories = CategoryModel::all([],'img,productList');
        return json($categories);
    }
}